package com.gmail.skwong.speedplayer;

/**
 * This class is for doing simple conversions to figure out what part of the
 * song should be at and where the progress bar should be when it is changed by
 * the user.
 * 
 * @author Stephen
 * 
 */
public class ProgressBarUtilities {

	public String milliSecondsToTimer(long milliseconds) {
		String finalTimer = "";
		String secondsString = "";

		int hours = (int) (milliseconds / (1000 * 60 * 60));
		int minutes = (int) (milliseconds % (1000 * 60 * 60)) / (1000 * 60);
		int seconds = (int) (milliseconds % (1000 * 60 * 60)) % (1000 * 60)
				/ 1000;

		if (hours > 0) {
			finalTimer = hours + ":";
		}
		if (seconds < 10) {
			secondsString = "0" + seconds;
		} else {
			secondsString = "" + seconds;
		}

		finalTimer += minutes + ":" + secondsString;

		return finalTimer;
	}

	public int getProgressPercentage(long currentDuration, long totalDuration) {
		Double percentage = (double) 0;

		long currentSeconds = (int) (currentDuration / 1000);
		long totalSeconds = (int) (totalDuration / 1000);

		percentage = ((double) currentSeconds / totalSeconds) * 100;

		return percentage.intValue();
	}

	public int progressToTimer(int progress, int totalDuration) {
		int currentDuration = 0;
		totalDuration = (int) (totalDuration / 1000);
		currentDuration = (int) ((((double) progress) / 100) * totalDuration);

		// return current duration in milliseconds
		return currentDuration * 1000;
	}
}
